/***************************************************************************************************
		* The Global Persistence of Work from Home

	This code produces Supplemental Figures A1 and A2 in the paper. 
	
	Both Figures use "GSWA_w4" data, with GSWA responses from wave 4 (2024/25) in 40 countries, and "CompletionRates.dta" with survey completion rates 
	
	Figure A1 uses "GSWA_w4" data, with GSWA responses from wave 2 (2022), 3 (2023) and 4 (2024/25) in a panel of 23 countries.

	Figure A2 uses "GSWA_w4" data, with GSWA responses from wave 4 (2024/25) in 40 countries.
 	
***************************************************************************************************/




		**** PATHS:
		
		gl path "C:\Users\pz0511\Dropbox\GlobalWFH\Global WFH 2024-25\PNAS Brief Report\Replication Package/"

		cd "${path}"

		
		
		**** Globals:
		
		* The global below is used in Figure A1. 
		
gl country_order `" `"Australia"' `"Canada"' `"Ireland"' `"New Zealand"' `"UK"' `"USA"' `"Austria"' `"Czech Rep."' `"Denmark"' `"Finland"' `"France"' `"Germany"' `"Greece"' `"Hungary"' `"Italy"' `"Netherlands"' `"Norway"' `"Poland"' `"Portugal"' `"Romania"' `"Spain"' `"Sweden"' `"Türkiye"' `"Argentina"' `"Brazil"' `"Chile"' `"Mexico"' `"Egypt"' `"Nigeria"' `"South Africa"' `"China"' `"India"' `"Japan"' `"Malaysia"' `"Singapore"' `"South Korea"' `"Taiwan"' `"Thailand"' `"The Philippines"' `"Vietnam"'  "'



		gl coefplot_rows_continents  `" c1 = "{bf: Average}"  "'
		local jj = 1
		foreach cntry of global country_order {
			local jj = `jj' + 1
			gl coefplot_rows_continents `"  ${coefplot_rows_continents} c`jj' = "`cntry'"  "'
		}

		
		
		
********************************************************************************
****** Figure A1: Completion Time by Country
****** Figure A2: Completion Time and WFH levels
********************************************************************************


use "Data/GSWA_w4", clear


* Merge with supplementary information:

merge m:1 country using "Supplemental Information/Completion_rate.dta"
drop _merge




replace completion_rate = 100*completion_rate


* Figure A1: Completion Time by Country
	foreach var of varlist completion_rate {
matrix results = J(1,41,.)

* Mean over all countries
mean `var', over(order_countries)

matrix results[1,2.41] = r(table)[1,1..40]

* The overall average is 77.51:
matrix results[1,1] =  77.51

 

	* Graphical decisions:
 * X-axis title:
local ytitles `" "Completion rate"  "'

* X-axis numeric labels:
local ylabels `"0(20)100"'

* Number of decimals in the figure:
local decval 0
local mlabel `"  string(@b, "%5.`decval'f") "'



** For graphical purposes, divide results in a matrix in each continent
matrix ress1 = results[1,1] // Average
matrix ress2 = results[1,2..7] // English Speaking
matrix ress3 = results[1,8..24] // Europe
matrix ress4 = results[1,25..28] // Latin America
matrix ress5 = results[1,29..31] // Africa
matrix ress6 = results[1,32..41] // Asia	


* Version 2:
coefplot (matrix(ress1), recast(bar) bcolor(black*0.9)) ///
		 (matrix(ress2), recast(bar) bcolor(cranberry*1.4)) ///
		 (matrix(ress3), recast(bar) bcolor(ebblue*1.4)) ///
		 (matrix(ress4), recast(bar) bcolor(gold*0.6)) ///
		 (matrix(ress5), recast(bar) bcolor(dkorange)) ///
		 (matrix(ress6), recast(bar) bcolor(forest_green*0.75)) ///
		 (matrix(results), mlabel(`mlabel')  mlabposition(3) mlabsize(vsmall) mlabcolor(black) mcolor(none) msize(vtiny) msymbol(d)) ,  ///
		legend(off) coeflabels(${coefplot_rows_continents}, labsize(tiny)) ///
		xlabel(`ylabels')  offset(0)  xtitle(`ytitles', size(small)) ///
		ylabel(, labsize(vsmall)) graphregion(color(white)) grid(none) ///
		fintensity(inten90) headings(c2 = "{bf:English Speaking}" c8 ="{bf:Europe}"  c25 = "{bf:Latin America}" c29 = "{bf:Africa}" c32 = "{bf:Asia}", gap(0.3) labsize(vsmall)) 

		* Save graph
		gr export "Output/FigureA1.png", replace
		gr export "Output/FigureA1.eps", replace as(eps)
			
			
	


		}

		
****************************************************************
****** Figure A2: Completion Time and WFH levels
****************************************************************

		
		collapse n_wfh completion_rate, by(country)
		
		twoway (scatter n_wfh completion_rate) (lfit n_wfh completion_rate, range(50 100)),  legend(order(2 "Linear fit") pos(5) ring(0)) xlabel(50 "50" 60 "60" 70 "70" 80 "80" 90 "90" 100 "100") ylabel(0(0.5)2) xtitle("Completion rate") ytitle("Number of days WFH this week")
		
				* Save graph
		gr export "Output/FigureA2.png", replace
		gr export "Output/FigureA2.eps", replace as(eps)
		
		* Regression coefficient of 0.0042 (0.0045). P=0.353
		reg n_wfh completion_rate













